function model = model_setup(reso,fov,wf)
% MODEL_SETUP Set up various parameters for PARSE image model
%
% MODEL_SETUP initializes various parameters and arrays, depending on the
% image side resolution RESO, the FOV in cm, and the complex parameter
% weights WF for the exponential parameters components.  
% Returns these calculated parameters:
%     model.wfi = 3e-05;  % relative scaling of exponential imaginary
%     model.wfr = 1e-05;  % relative scaling of exponential real
%     model.x  % vector of row coordinates of ROS in cm (optional)
%     model.y  % vector of col coordinates of ROS in cm (optional)
%     model.N  % number of voxels in ROS (optional)
%     model.pvec  % concatenated vector of ampl and decay/freq parameters in ROS (opt)
%     model.mask  % binary image of ROS (optional)
%
% Note that the origin is the upper left corner for indices, but the center
% index is RESO/2 for calculating x and y coordinates.  x is the row
% variable and y is the column variable.

model.reso = reso;
model.wfi = imag(wf);  % relative scaling of exponential imaginary
model.wfr = real(wf);  % relative scaling of exponential real

% set up 1-D arrays representing locations of pixels of interest
model.ix1d = ((1:reso)-(reso/2+1))*fov/reso;  % actual x coordinates in cm
XX = single(meshgrid(model.ix1d));
xdist = sqrt(XX.^2+XX'.^2);
model.mask = xdist<(1/2)*fov;

% list pixel coordinates within center mask
[model.ix,model.iy] = find(model.mask);
model.N = size(model.ix,1);  % number of unknown voxels in FOV

% set up one-D arrays of spatial coordinate values x and y within center mask
model.x = zeros(1,model.N,'single');
model.y = model.x;
% for nl = 1:model.N
%     model.y(nl) = XX(model.ix(nl),model.iy(nl));
%     model.x(nl) = XX(model.iy(nl),model.ix(nl));
% end

nl = 1:model.N;
model.y = XX(sub2ind(size(XX),model.ix(nl),model.iy(nl)));
model.x = XX(sub2ind(size(XX),model.iy(nl),model.ix(nl)));
